/**
 * Copyright (C) 2012  The CFuture Android SDK Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lurencun.android.toolkit.database;

import com.lurencun.android.toolkit.HasContext;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;


/**
 * 
 * @author cfuture.chenyoca [桥下一粒砂] (chenyoca@163.com)
 * @date 2012-2-15
 */
public class ShareDBHelper extends HasContext {

	private SharedPreferences db;

	public ShareDBHelper(Context context, String dbName) {
		super(context);
		db = mContext.getSharedPreferences(dbName, 0);
	}

	public void put(String key, Object val) {
		Editor editor = db.edit();
		if(val instanceof String){
			editor.putString(key, val.toString());
		}else if(val instanceof Integer){
			editor.putInt(key, (Integer)val);
		}else if(val instanceof Float){
			editor.putFloat(key, (Float)val);
		}else if(val instanceof Long){
			editor.putLong(key, (Long)val);
		}else if(val instanceof Boolean){
			editor.putBoolean(key, (Boolean)val);
		}
		editor.commit();
	}
	
	public int getInt(String key){
		return db.getInt(key, 0); 
	}
	
	public int getInt(String key,int deftVal){
		return db.getInt(key, deftVal);
	}
	
	public boolean getBoolean(String key){
		return db.getBoolean(key, false);
	}

	public boolean getBoolean(String key,boolean defValue){
		return db.getBoolean(key, defValue);
	}
	
	public String getString(String key){
		return db.getString(key, "");
	}
	
	public String getString(String key,String defValue){
		return db.getString(key, defValue);
	}
	
	public long getLong(String key){
		return db.getLong(key, 0L);
	}
	
	public long getLong(String key,Long defValue){
		return db.getLong(key, defValue);
	}
	
	public float getFloat(String key){
		return db.getFloat(key, 0L);
	}
	
	public float getFloat(String key,Float defValue){
		return db.getFloat(key, defValue);
	}
	
}
